function rankings = parseESPN(filename)

% PARSEESPN - parse a csv ranking file

    fid = fopen(filename);
    if fid < 0
        rankings = [];
        return;
    end
    count = 1;
    tline = fgetl(fid);
    [n,ca,py,ptd,pi,ra,ry,rtd,recnum,recyd,rectd,reg,ppr] = ...
        strread(tline,'%s%s%s%s%s%s%s%s%s%s%s%s%s','delimiter','\t');
    while 1
        tline = fgetl(fid);
        if ~ischar(tline), break, end
        [nstr,ca,py,ptd,pi,ra,ry,rtd,recnum,recyd,rectd,reg,ppr] = ...
            strread(tline,'%s%s%s%s%s%s%s%s%s%s%s%s%s','delimiter','\t');
        
        nameStr = nstr{1};
        [n rem] = strtok(nameStr(2:end),',');
        [t rem] = strtok(rem(2:end),' ');
        [p rem] = strtok(rem(2:end),' "');
        name{count} = n;
        pos(count) = positionNum(p);
        team{count} = t;
        rank(count) = str2double(ppr{1});
        count = count + 1;
    end

    rankings.name = name;
    rankings.pos = pos;
    rankings.team = team;
    rankings.rank = rank;
end

function n = positionNum(posstr)
    
    if strcmpi(posstr,'RB')
        n = 1;
    elseif strcmpi(posstr,'QB')
        n = 2;
    elseif strcmpi(posstr,'WR')
        n = 3;
    elseif strcmpi(posstr,'TE')
        n = 4;
    elseif strcmpi(posstr,'K')
        n = 5;
    elseif strcmpi(posstr,'D/ST')
        n = 6;
    else
        fprintf('UNKOWN POSITION STRING');
        n = -1;
    end
end
